package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.globle.Constant;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityGoodsSizeInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * Created by zlz
 * on  4/18/21
 */
public class VMGoodsSizeDetail extends ViewModel {

    private MutableLiveData<List<EntityGoodsSizeInfo>> liveGoodSizeInfo = new MutableLiveData<>();


    public MutableLiveData<List<EntityGoodsSizeInfo>> getLiveGoodSizeInfo() {
        return liveGoodSizeInfo;
    }


    public void requestData(){


        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {


                        liveGoodSizeInfo.setValue(createTestData());
                    }
                });



    }


//<editor-fold defaultState="collapsed" desc="测试">


    private  List<EntityGoodsSizeInfo> createTestData(){


        List<EntityGoodsSizeInfo> list = new ArrayList<>();


        for (int i = 0; i < 10; i++) {

            EntityGoodsSizeInfo entityGoodsSizeInfo  =new EntityGoodsSizeInfo();
            entityGoodsSizeInfo.setBatch("1");
            entityGoodsSizeInfo.setDays("1");
            entityGoodsSizeInfo.setGain("+1");
            entityGoodsSizeInfo.setNum("1");
            entityGoodsSizeInfo.setPrice(Constant.Character.CNY+"1");


            if( i==0 ){

                entityGoodsSizeInfo.setGain("-1");

            }

            list.add(entityGoodsSizeInfo);
        }


        return list;
    }



// </editor-fold>

}
